﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class product : System.Web.UI.Page
{
    eStoreDataContext db = new eStoreDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
       // var tour = db.Tours.ToList();
        //if (Request["LocationId"] != null)
        //{
        //    int LocationId = int.Parse(Request["LocationId"]);
        //    var result = from ct in db.LocationTours
        //                 where ct.LocationId == LocationId
        //                 join l in db.Tours on ct.TourId equals l.TourId
        //                 select new
        //                 {
        //                     l.Name,
        //                     l.TourId,
        //                     l.TourDate,
        //                     l.UnitPrice
        //                 };
        //    ListView1.DataSource = result;
        //    ListView1.DataBind();
        //}
        
        if (RouteData.Values["CategoryId"] != null)
        {

            int CategoryId = int.Parse(RouteData.Values["CategoryId"].ToString());
            //Response.Write("category" + CategoryId);
            var tour = db.Tours.Where(p => p.CategoryId == CategoryId).ToList();
            ListView1.DataSource = tour;
            ListView1.DataBind();

            //site mapth
            string Categoryname = "";
            String Language = Thread.CurrentThread.CurrentCulture.DisplayName;
            if (Language.ToLower().Contains("vietnam"))
            {
                Label1.Text = db.Categories.Single(c => c.CategoryId == CategoryId).NameVN.ToString();
                Categoryname = db.Categories.Single(c => c.CategoryId == CategoryId).NameVN.ToString();
            }
            else
            {
                Label1.Text = db.Categories.Single(c => c.CategoryId == CategoryId).Name.ToString();
                Categoryname = db.Categories.Single(c => c.CategoryId == CategoryId).Name.ToString();
            }

            int CateId = int.Parse(db.Categories.Single(c => c.CategoryId == CategoryId).CategoryId.ToString());

            lblsitemapth.Text = " &raquo; " + Categoryname;
        }
       else if (RouteData.Values["LocationId"] != null)
        {
           // Response.Write("LocationId" + RouteData.Values["LocationId"]);
            var tour = db.Tours.ToList();
            String lts = String.Join(",", db.LocationTours.Where(n => n.LocationId == int.Parse(RouteData.Values["LocationId"].ToString())).Select(n => n.TourId.ToString()).ToList());
            
            ListView1.DataSource = tour.Where(n=>lts.Contains(n.TourId+"")).ToList();
            ListView1.DataBind();
           


           //site mapth
            string CateName = "";
            string LocationName = "";
            String Language = Thread.CurrentThread.CurrentCulture.DisplayName;
            if (Language.ToLower().Contains("vietnam"))
            {
                Label1.Text = db.Locations.Single(c => c.LocationId == int.Parse(RouteData.Values["LocationId"].ToString())).NameVN.ToString();
                CateName = db.Locations.Single(c => c.LocationId == int.Parse(RouteData.Values["LocationId"].ToString())).Category.NameVN.ToString();
                LocationName = db.Locations.Single(c => c.LocationId == int.Parse(RouteData.Values["LocationId"].ToString())).NameVN.ToString();
            }
            else
            {
                Label1.Text = db.Locations.Single(c => c.LocationId == int.Parse(RouteData.Values["LocationId"].ToString())).Name.ToString();
                CateName = db.Locations.Single(c => c.LocationId == int.Parse(RouteData.Values["LocationId"].ToString())).Category.Name.ToString();
                LocationName = db.Locations.Single(c => c.LocationId == int.Parse(RouteData.Values["LocationId"].ToString())).Name.ToString();
            }

            int id= int.Parse(db.Locations.Single(c => c.LocationId == int.Parse(RouteData.Values["LocationId"].ToString())).Category.CategoryId.ToString());

            lblsitemapth.Text = " &raquo; <a href='/" + CateName.ToString().ToAscii() + "-" + id + ".html'>" + CateName + "</a>";
            lblsitemapth.Text += " &raquo; ";
            lblsitemapth.Text += LocationName;
        }

         
    }
    public String Name
    {
        get
        {
            String Language = Thread.CurrentThread.CurrentCulture.DisplayName;
            if (Language.ToLower().Contains("vietnam"))
            {
                return "NameVN";
            }
            else
            {
                return "Name";
            }

        }
    }
    
}